# Copyright 1999-2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/app-admin/ulogd/ulogd-1.24.ebuild,v 1.6 2007/07/07 04:21:29 vapier Exp $

inherit eutils flag-o-matic autotools

DESCRIPTION="A userspace logging daemon for netfilter/iptables related logging"
HOMEPAGE="http://netfilter.org/projects/ulogd/index.html"
SRC_URI="http://ftp.netfilter.org/pub/ulogd/${P}.tar.bz2"

LICENSE="GPL-2"
SLOT="0"
KEYWORDS="~amd64 ~ia64 ~ppc -sparc ~x86"
IUSE="mysql postgres sqlite3 log-ip-as-string"

DEPEND="net-firewall/iptables
	mysql? ( virtual/mysql )
	postgres? ( dev-db/postgresql )
        sqlite3? ( >=dev-db/sqlite-3.2 )"

src_unpack() {
	unpack ${A}

	cd "${S}"
	epatch "${FILESDIR}"/configure-fixes.patch
        epatch "${FILESDIR}"/altlinux/ulogd-1.24-fopen.patch
        epatch "${FILESDIR}"/altlinux/ulogd-1.24-fixes-base.patch
        epatch "${FILESDIR}"/altlinux/ulogd-1.24-user-option.patch
        epatch "${FILESDIR}"/altlinux/ulogd-1.24-sqlite.patch
        epatch "${FILESDIR}"/altlinux/ulogd-1.24-fixes-sqlite3.patch
}

src_compile() {
	# enables logfiles over 2G (#74924)
	append-lfs-flags

        my_conf="$(use_with mysql) $(use_with postgres pgsql) $(use_with sqlite3 sqlite3)"
        
        if use log-ip-as-string ; then
            use mysql && my_conf="${my_conf} --with-mysql-log-ip-as-string"
    	    use postgres && my_conf="${my_conf} --with-pgsql-log-ip-as-string"
            use sqlite3 && my_conf="${my_conf} --with-sqlite3-log-ip-as-string"
        fi
        
	ewarn "Regenerating build system (this may take a bit)..."
	eautoconf || die "Autoreconf failed"
	econf ${my_conf} || die "configure failed"

	# Configure uses incorrect syntax for ld
	use mysql && sed -i -e "s:-Wl,::g" Rules.make

	# not parallel make safe: bug #128976
	emake -j1 || die "make failed"
}

src_install() {
	# the Makefile seems to be "broken" -
	# it relies on the existance of /usr, /etc ..
	dodir /usr/sbin

	make DESTDIR="${D}" install || die "install failed"

	newinitd "${FILESDIR}"/ulogd-0.98 ulogd

	dodoc README AUTHORS Changes
	cd doc/
	dodoc ulogd.txt ulogd.a4.ps

	use mysql && dodoc mysql.table mysql.table.ipaddr-as-string
	use postgres && dodoc pgsql.table
        use sqlite3 && dodoc sqlite3.table

	dohtml ulogd.html
}
